package cn.maydaymemory.mastery.command.api;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;

import java.lang.reflect.Field;

public class CommandManager {
    private static CommandMap commandMap;
    static {
        try
        {
            Field field = Bukkit.getServer().getClass().getDeclaredField("commandMap");
            field.setAccessible(true);
            commandMap= (CommandMap)field.get(Bukkit.getServer());
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public static void register(Command command) {
        if(commandMap!=null)
            commandMap.register(command.getName(), command);
    }

    public static void register(String name , CommandStructure structure) {
        register(new SuperCommand(name,structure));
    }
}
